/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package interface_graphique;

import ClassesJava.*;
import static interface_graphique.MenuPrincipale.menu;
import java.awt.Color;
import java.awt.Component;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.util.Vector;
import javax.swing.JTable;
import javax.swing.JTextArea;
import javax.swing.UIManager;
import javax.swing.border.EmptyBorder;
import javax.swing.table.TableCellRenderer;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Map;


/**
 *
 * @author ISMAYLOULABBIHI
 */
public class EmploieDeTemps extends javax.swing.JFrame {

    public static EmploieDeTemps E;
    private Filiere fl;
    public static Filiere FChoise;
    public Salle salle;
    public Matieres matieres;
    public Professeur professeur;
    public Cour co;
    ArrayList<Filiere> listeF = new ArrayList();
    ArrayList<Cour> listeC = new ArrayList();

    /**
     * Creates new form EmploieDeTemps
     */
    public EmploieDeTemps() {
       
        initComponents();
         setLocationRelativeTo(null);
        fl = new Filiere();
        FChoise = new Filiere();
        salle = new Salle();
        matieres = new Matieres();
        professeur = new Professeur();
        co = new Cour();
        afficherfiliere();
        
       
       

    }

    public void afficherfiliere() {
        jComFiliare.removeAllItems();
        Vector<Filiere> res = new Vector();
        res = fl.getFilieres();
        for (int i = 0; i < res.size(); i++) {
            listeF.add(res.get(i));
            jComFiliare.addItem(res.get(i).getNom() + "    " + res.get(i).getNiveau());

        }
    }

    public void afficherCours() {
        jTEmploi.setDefaultRenderer(String.class, new MultiLineCellRenderer());
       
        Vector<Cour> res = new Vector();
        res = co.getCourByFiliere(FChoise);
        int j = 0;
        int k = 0;
        for (int i = 0; i < res.size(); i++) {
            j = i % 6;
            listeC.add(res.get(i));
            if (res.get(i).getNumMatier() != 0) {
                salle=salle.getSalleById(res.get(i).getNumsalle());
                jTEmploi.setValueAt( matieres.getMatiereByID(res.get(i).getNumMatier()).getLabel()
                        + "\n" + salle.gettype() + ": "+ salle.getbloc()
                        +"\nProf:"+ professeur.getProfesseurById(res.get(i).getIdProf()).getNom(), k, j);
                
            } else {
                jTEmploi.setValueAt("", k, j);
            }
            if (j == 5) k++;
            }
        
    }

    public void getZone() {
        co.setRow(jTEmploi.getSelectedRow());
        co.setCol(jTEmploi.getSelectedColumn());

    }

//    public void afficherSalles() {
//        jComSalle.removeAllItems();
//        Vector<Salle> res = new Vector();
//        res = s.getSalle();
//        for (int i = 0; i < res.size(); i++) {
//            jComSalle.addItem(res.get(i).getbloc() + "    " + res.get(i).gettype());
//
//        }
//    }
//     public void afficherMatieres() {
//        jComMatiere.removeAllItems();
//        Vector<Matieres> res = new Vector();
//        res = m.getMatieres();
//        for (int i = 0; i < res.size(); i++) {
//            jComMatiere.addItem(res.get(i).getLabel());
//
//        }
//    }
//      public void afficherProfesseur() {
//        jComProf.removeAllItems();
//        Vector<Professeur> res = new Vector();
//        res = p.getProfesseur();
//        for (int i = 0; i < res.size(); i++) {
//            jComProf.addItem(res.get(i).getNom() + "  "+ res.get(i).getPrenom());
//
//        }
//    }
    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jScrollPane1 = new javax.swing.JScrollPane();
        jTable1 = new javax.swing.JTable();
        jScrollPane2 = new javax.swing.JScrollPane();
        jTEmploi = new javax.swing.JTable();
        jLabel1 = new javax.swing.JLabel();
        jComFiliare = new javax.swing.JComboBox();
        jLabel3 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        sui = new javax.swing.JLabel();
        imp = new javax.swing.JLabel();
        btPre = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();

        jTable1.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        jScrollPane1.setViewportView(jTable1);

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setBackground(java.awt.Color.gray);
        setUndecorated(true);
        addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseExited(java.awt.event.MouseEvent evt) {
                formMouseExited(evt);
            }
        });
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosed(java.awt.event.WindowEvent evt) {
                formWindowClosed(evt);
            }
        });
        getContentPane().setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        jTEmploi.setAutoCreateRowSorter(true);
        jTEmploi.setBackground(new java.awt.Color(204, 204, 204));
        jTEmploi.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null, null, null},
                {null, null, null, null, null, null},
                {null, null, null, null, null, null},
                {null, null, null, null, null, null}
            },
            new String [] {
                "", "", "", "", "", ""
            }
        ) {
            Class[] types = new Class [] {
                java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }
        });
        jTEmploi.setToolTipText("");
        jTEmploi.setAlignmentY(8);
        jTEmploi.setCellSelectionEnabled(true);
        jTEmploi.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
        jTEmploi.setEditingRow(4);
        jTEmploi.setGridColor(new java.awt.Color(102, 102, 102));
        jTEmploi.setIntercellSpacing(new java.awt.Dimension(0, 0));
        jTEmploi.setMaximumSize(new java.awt.Dimension(2147483647, 500));
        jTEmploi.setMinimumSize(new java.awt.Dimension(150, 200));
        jTEmploi.setPreferredSize(new java.awt.Dimension(450, 300));
        jTEmploi.setRowHeight(72);
        jTEmploi.setRowMargin(5);
        jTEmploi.setSelectionForeground(new java.awt.Color(153, 153, 255));
        jTEmploi.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        jTEmploi.setSurrendersFocusOnKeystroke(true);
        jTEmploi.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jTEmploiMouseClicked(evt);
            }
        });
        jScrollPane2.setViewportView(jTEmploi);

        getContentPane().add(jScrollPane2, new org.netbeans.lib.awtextra.AbsoluteConstraints(150, 220, 690, 320));

        jLabel1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/emloie.jpg"))); // NOI18N
        getContentPane().add(jLabel1, new org.netbeans.lib.awtextra.AbsoluteConstraints(30, 150, 810, 390));

        jComFiliare.setFont(new java.awt.Font("Wide Latin", 0, 14)); // NOI18N
        jComFiliare.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
        jComFiliare.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                jComFiliareItemStateChanged(evt);
            }
        });
        jComFiliare.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jComFiliareActionPerformed(evt);
            }
        });
        getContentPane().add(jComFiliare, new org.netbeans.lib.awtextra.AbsoluteConstraints(140, 90, 210, 30));

        jLabel3.setFont(new java.awt.Font("Script MT Bold", 0, 24)); // NOI18N
        jLabel3.setText("Fliaire:");
        getContentPane().add(jLabel3, new org.netbeans.lib.awtextra.AbsoluteConstraints(50, 90, -1, -1));

        jLabel2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/titreEmpolie.png"))); // NOI18N
        getContentPane().add(jLabel2, new org.netbeans.lib.awtextra.AbsoluteConstraints(130, 0, -1, 80));

        jLabel6.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/redoit.png"))); // NOI18N
        jLabel6.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        jLabel6.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jLabel6MouseClicked(evt);
            }
        });
        getContentPane().add(jLabel6, new org.netbeans.lib.awtextra.AbsoluteConstraints(800, 0, -1, -1));

        jLabel7.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/quite.png"))); // NOI18N
        jLabel7.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        jLabel7.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jLabel7MouseClicked(evt);
            }
        });
        getContentPane().add(jLabel7, new org.netbeans.lib.awtextra.AbsoluteConstraints(840, 0, -1, -1));

        sui.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/suivent.png"))); // NOI18N
        sui.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        sui.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                suiMouseClicked(evt);
            }
            public void mouseEntered(java.awt.event.MouseEvent evt) {
                suiMouseEntered(evt);
            }
            public void mouseExited(java.awt.event.MouseEvent evt) {
                suiMouseExited(evt);
            }
        });
        getContentPane().add(sui, new org.netbeans.lib.awtextra.AbsoluteConstraints(510, 90, 90, 30));

        imp.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/IMP.png"))); // NOI18N
        imp.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        imp.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                impMouseClicked(evt);
            }
            public void mouseEntered(java.awt.event.MouseEvent evt) {
                impMouseEntered(evt);
            }
            public void mouseExited(java.awt.event.MouseEvent evt) {
                impMouseExited(evt);
            }
        });
        getContentPane().add(imp, new org.netbeans.lib.awtextra.AbsoluteConstraints(620, 90, 90, 30));

        btPre.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/president.png"))); // NOI18N
        btPre.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        btPre.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                btPreMouseClicked(evt);
            }
            public void mouseEntered(java.awt.event.MouseEvent evt) {
                btPreMouseEntered(evt);
            }
            public void mouseExited(java.awt.event.MouseEvent evt) {
                btPreMouseExited(evt);
            }
        });
        getContentPane().add(btPre, new org.netbeans.lib.awtextra.AbsoluteConstraints(400, 90, -1, -1));

        jLabel4.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/arirePlanEmpoie.jpg"))); // NOI18N
        jLabel4.setOpaque(true);
        getContentPane().add(jLabel4, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 0, 880, 550));

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jTEmploiMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jTEmploiMouseClicked
        getZone();
        if (evt.getClickCount() == 1) {
            TraiterZone t = new TraiterZone();
            t.setVisible(true);
            //co = new Cour();
        }
    }//GEN-LAST:event_jTEmploiMouseClicked
    public void setZone() {
        jTEmploi.setValueAt(co.getDescription(), co.getRow(), co.getCol());
    }
    private void formMouseExited(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_formMouseExited


    }//GEN-LAST:event_formMouseExited

    private void formWindowClosed(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosed

        menu.setVisible(true);

    }//GEN-LAST:event_formWindowClosed

    private void jComFiliareItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_jComFiliareItemStateChanged
        if (jComFiliare.getSelectedIndex() != -1) {
            FChoise = (Filiere) listeF.get(jComFiliare.getSelectedIndex());
            afficherCours();
        }
    }//GEN-LAST:event_jComFiliareItemStateChanged

    private void jLabel7MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jLabel7MouseClicked
         menu.setVisible(true);
        this.setVisible(false);
        
    }//GEN-LAST:event_jLabel7MouseClicked

    private void jLabel6MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jLabel6MouseClicked
        // TODO add your handling code here:
    }//GEN-LAST:event_jLabel6MouseClicked

    private void suiMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_suiMouseClicked
        // TODO add your handling code here:
        if(jComFiliare.getSelectedIndex()< jComFiliare.countComponents())
            jComFiliare.setSelectedIndex(jComFiliare.getSelectedIndex()+1);
    }//GEN-LAST:event_suiMouseClicked

    private void btPreMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_btPreMouseClicked
        // TODO add your handling code here:
        if(jComFiliare.getSelectedIndex()>0)
            jComFiliare.setSelectedIndex(jComFiliare.getSelectedIndex()-1);
    }//GEN-LAST:event_btPreMouseClicked

    private void btPreMouseEntered(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_btPreMouseEntered
         btPre.setOpaque(true);
        btPre.setBackground(Color.BLUE);
        
       
    }//GEN-LAST:event_btPreMouseEntered

    private void impMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_impMouseClicked
    
    }//GEN-LAST:event_impMouseClicked

    private void jComFiliareActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jComFiliareActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jComFiliareActionPerformed

    private void btPreMouseExited(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_btPreMouseExited
        // TODO add your handling code here:
        btPre.setBackground(Color.red);
        btPre.setOpaque(false);
       
    }//GEN-LAST:event_btPreMouseExited

    private void suiMouseEntered(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_suiMouseEntered
        // TODO add your handling code here:
         sui.setOpaque(true);
        sui.setBackground(Color.BLUE);
    }//GEN-LAST:event_suiMouseEntered

    private void suiMouseExited(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_suiMouseExited
        // TODO add your handling code here:
        sui.setOpaque(false);
        sui.setBackground(Color.red);
    }//GEN-LAST:event_suiMouseExited

    private void impMouseEntered(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_impMouseEntered
       imp.setOpaque(true);
        imp.setBackground(Color.BLUE);
    }//GEN-LAST:event_impMouseEntered

    private void impMouseExited(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_impMouseExited
       imp.setOpaque(false);
        imp.setBackground(Color.red);
    }//GEN-LAST:event_impMouseExited

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(EmploieDeTemps.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(EmploieDeTemps.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(EmploieDeTemps.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(EmploieDeTemps.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {

                //E.setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel btPre;
    private javax.swing.JLabel imp;
    private javax.swing.JComboBox jComFiliare;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JTable jTEmploi;
    private javax.swing.JTable jTable1;
    private javax.swing.JLabel sui;
    // End of variables declaration//GEN-END:variables
}

class MultiLineCellRenderer extends JTextArea implements TableCellRenderer {

  public MultiLineCellRenderer() {
    setLineWrap(true);
    setWrapStyleWord(true);
    setOpaque(true);
    
  }

  public Component getTableCellRendererComponent(JTable table, Object value,
      boolean isSelected, boolean hasFocus, int row, int column) {
    if (isSelected) {
      setForeground(table.getSelectionForeground());
      setBackground(table.getSelectionBackground());
    } else {
      setForeground(table.getForeground());
      setBackground(table.getBackground());
    }

    setText((value == null) ? "" : value.toString());
    return this;
  }
}